package com.xkstream.client.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.xkstream.client.R;
import com.xkstream.client.base.BaseRecycleViewAdapter;
import com.xkstream.client.entity.kt.RewardData;
import com.xkstream.client.utils.DateUtil;
import com.xkstream.client.view.GainsProgressbar;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xiaoyi on 2017-9-27.
 */

public class RewardAdapter extends BaseRecycleViewAdapter {
    private List<RewardData.GiftNumberValue> mDatas;
    private double maxValue;

    public RewardAdapter(Context mContext, List<RewardData.GiftNumberValue> mDatas) {
        super(mContext);
        this.mDatas = mDatas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.layout_reward_item, parent, false);
        ItemHolder holder = new ItemHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RewardData.GiftNumberValue reward = mDatas.get(position);
        ItemHolder itemHolder = (ItemHolder) holder;
        itemHolder.gpGains.setMaxValue(maxValue);
        if (position == 0) {
            itemHolder.gpGains.setProgressColor(Color.parseColor("#ffcc00"));
        } else {
            itemHolder.gpGains.setProgressColor(Color.parseColor("#cccccc"));
        }
        itemHolder.gpGains.setProgress((int) reward.getAnchor_get_value());
        itemHolder.gpGains.setTime(DateUtil.formatTime(reward.getGift_time(), "yyyy-MM-dd"));
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.gpGains)
        GainsProgressbar gpGains;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void filterData() {
        for (RewardData.GiftNumberValue data : mDatas) {
            maxValue = Math.max(data.getAnchor_get_value(), maxValue);
        }
    }

    public void customNotifyDataSetChanged() {
        filterData();
        notifyDataSetChanged();
    }
}
